﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper {
	public class PayNotifyMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public PayNotifyMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<pay_notify_dto, PayNotify>()
				.ForMember(dest => dest.OrderNo, src => src.MapFrom(c => c.order_no))
				.ForMember(dest => dest.PayChannel, src => src.MapFrom(c => c.pay_channel))
				.ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no))
				.ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()));
			_cfg.CreateMap<PayNotify, pay_notify_dto>()
				.ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
				.ForMember(dest => dest.pay_channel, src => src.MapFrom(c => c.PayChannel))
				.ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.MerchantNo))
				.ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()));
		}
	}
}